using System;
using System.DirectoryServices;

namespace OLAActiveDirectory.Management
{
    public interface IADPasswdManager
    {
        void ChangePassword(IADUser objUser, string strOldPasswd, string strNewPasswd);
        void SetPassword(IADUser objUser, string strPasswd);
    }
    public class ADPasswdManager : IADPasswdManager
    {
        public ADPasswdManager()
        {
        }
        public void SetPassword(IADUser objUser, string strPasswd)
        {
            DirectoryEntry objLoginEntry = objUser.DirectoryEntry;
            if (objLoginEntry != null)
            {
                objLoginEntry.Invoke("SetPassword", new object[] { strPasswd });
                objLoginEntry.CommitChanges();
            }
        }
        public void ChangePassword(IADUser objUser, string strOldPasswd, string strNewPasswd)
        {
            DirectoryEntry objLoginEntry = objUser.DirectoryEntry;
            if (objLoginEntry != null)
            {
                objLoginEntry.Invoke("ChangePassword", new object[] { strOldPasswd, strNewPasswd });
                objLoginEntry.CommitChanges();
            }
        }
    }
}
